package graph.paint;

import graph.Edge;
import graph.Graph;
import graph.Node;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

public class GraphPainter<T,V> {
	public GraphPainter(ViewPort viewPort, NodePainter<T> nodePainter, EdgePainter<T,V> edgePainter) {
		this.viewPort = viewPort;
		this.nodePainter = nodePainter;
		this.edgePainter = edgePainter;
	}
	private ViewPort viewPort;
	NodePainter<T> nodePainter;
	EdgePainter<T,V> edgePainter;
	
	/*
	protected static void drawText(GC gc, String string, int x, int y, int height) {
		Font origfont = gc.getFont();
		FontData[] data = origfont.getFontData();
		for (FontData d : data) {
			d.setHeight(height);
		}
		Font font = new Font(origfont.getDevice(), data);
		gc.setFont(font);
		Color bg = gc.getBackground();
		gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_YELLOW));
		gc.drawText(string, x, y);
		gc.setBackground(bg);
		Point p = gc.textExtent(string);
		gc.setFont(origfont);
		font.dispose();
		gc.drawRectangle(x-1, y-1, p.x, p.y+1);
	}
	*/
	public void setArea(Rectangle rect) {
		viewPort.setArea(rect);
	}

	public void paint(Graph<T,V> graph, GC gc) {
		for (Edge<T,V> edge : graph.getEdges()) {
			edgePainter.paint(gc, edge, viewPort, nodePainter);
		}
		for (Node<T> node : graph.getNodes()) {
			nodePainter.paint(gc, viewPort, node);
		}
	}

}
